#include <QCoreApplication>
#include <iostream>
#include <vector>
#include <set>
#include <string>
using namespace std;

class CentipedeSocks
{
public:
    int fewestSocks(int C, int F, vector <int> sockCounts)
    {
        int ans=0;
        vector<int> sock(sockCounts),sock2(sockCounts);
        //检查成立条件
        for (int j=1;j<=C;j++)
        {
            for(int i=0;i<sockCounts.size();i++)
            {
                if(sock[i]>=F)
                {
                    sock[i]-=F;
                    break;
                }
                if(i==sockCounts.size()-1&&sock[i]<F)
                    return -1;
            }
        }
        //计算去袜子的数量
        for (int j=1;j<=C;j++)
        {
            for(int i=0;i<sockCounts.size();i++)
            {
                if(sock2[i]>=F)
                {
                    sock2[i]-=F-1;
                    ans+=F-1;
                }
                else if(sock2[i]==sockCounts[i])
                {
                    ans+=sock2[i];
                    sock2[i]=0;
                }
            }
        }
        ans+=C;
        return ans;
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    int c =3;
    int f=10;
    vector<int> sock{11232131};
    CentipedeSocks test;
    cout<<test.fewestSocks(c,f,sock);

    return a.exec();
}
